package com.woniuxy.happylife.suggest.service.impl;

import com.woniuxy.happylife.entity.FormInline;
import com.woniuxy.happylife.entity.Suggests;
import com.woniuxy.happylife.suggest.dao.SuggestionDao;
import com.woniuxy.happylife.suggest.service.SuggestionService;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author Fu
 * @Date 2022-02-15 11:56
 */
@Service
public class SuggestionServiceImpl implements SuggestionService {
    @Resource
    SuggestionDao suggestionDao;
    @Autowired
    RabbitTemplate rabbitTemplate;
    public MessagePostProcessor message(){
        return message -> {
            message.getMessageProperties().setExpiration("10000");

            return message;
        };
    }
    @Override
    public void insert(Suggests suggests) {

        rabbitTemplate.convertAndSend("addSuggestTopic","addSuggest",suggests);


    }

    @Override
    public List<Suggests> findByCondition(FormInline formInline) {
        return suggestionDao.findByCondition(formInline);
    }


    @Override
    public int updateStatus(Suggests suggests) {
        return suggestionDao.updateStatus(suggests);
    }

    @Override
    public int deleteById(Integer suggestsId) {
        return suggestionDao.deleteById(suggestsId);
    }
}
